import Cookies from 'js-cookie'

const TokenKey = 'vue_admin_template_token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

/**
 * 获取token字符串,只是access_token的内容
 */
export function getRawToken() {
  const tokenStr = Cookies.get(TokenKey)
  if (tokenStr) {
    const { access_token, expireTime, refresh_token } = JSON.parse(tokenStr)
    return { access_token, expireTime, refresh_token }
  }
  return {}
}
